<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>
        账号: <input id="user" type="text">
    </p>
    <p>
        密码: <input id="pwd" type="text">
    </p>
    <p>
        <button id="btn">登录</button>
    </p>

    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
    <script>
        const user = document.getElementById("user")
        const pwd = document.getElementById("pwd")
        const btn = document.getElementById("btn")

        btn.addEventListener("click", () => {
            axios.post("/login", {
                userName: user.value,
                passWord: pwd.value
            }).then(res => {
                if (res.data.token) {
                    sessionStorage.setItem("token", res.data.token)
                    location.href = "./home.html"
                }
            })
        })
    </script>
</body>
</html>